﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using ESOL.Common.Entity;
using ESOL.Business.Prod;
//using ESOL.Services.DataContracts;
using BPM.Base.Tools;
using BPM.Foundation.PWService;
using ESOL.Business.Mst;
using ESOL.Business.Sales;
using ESOL.Business.Prod;
using System.Data;
using ESOL.Business.Bpt;
using BPM.Foundation.PWDB;

namespace ESOL.Services
{
    public partial class ProdService : IProdService
    {
        //public DataSet GetUiPoByCondition(int pageIndex, int pageCount, string condition)
        //{
        //    try
        //    {
        //        return ProdPoBs.GetUiPoByCondition(pageIndex, pageCount, condition);
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new FaultException<ProcessExecutionFault>
        //            (new ProcessExecutionFault(), ex.Message);
        //    }
        //}

        //public ProdPoEntity AddPo(ProdPoEntity po)
        //{
        //    try
        //    {
        //        po.Id = Guid.NewGuid().ToString();
        //        po.CreatedDate = DateTime.Now;
        //        po.UpdateDate = DateTime.Now;
        //        return ProdPoBs.InsertProdPo(po);
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new FaultException<ProcessExecutionFault>
        //            (new ProcessExecutionFault(), ex.Message);
        //    }
        //}

        //public bool UpdatePo(ProdPoEntity po)
        //{
        //    try
        //    {
        //        po.UpdateDate = DateTime.Now;
        //        return ProdPoBs.UpdateProdPo(po);
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new FaultException<ProcessExecutionFault>
        //            (new ProcessExecutionFault(), ex.Message);
        //    }
        //}

        /// <summary>
        /// PO拆单
        /// </summary>
        /// <param name="curPo"></param>
        /// <param name="splitPo"></param>
        /// <returns></returns>
        //public bool SplitPo(ProdPoEntity curPo, ProdPoEntity splitPo)
        //{
        //    try
        //    {
        //        curPo.UpdateDate = DateTime.Now;
        //        splitPo.Id = Guid.NewGuid().ToString();
        //        splitPo.CreatedDate = DateTime.Now;
        //        splitPo.UpdateDate = DateTime.Now;
        //        return ProdPoBs.SplitPo(curPo, splitPo);
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new FaultException<ProcessExecutionFault>
        //            (new ProcessExecutionFault(), ex.Message);
        //    }
        //}

        public ProdMaintainPo AddMaintainPo(ProdMaintainPo mp)
        {
            try
            {
                if (mp == null)
                    return null;
                if (string.IsNullOrEmpty(mp.Id))
                    return null;
                mp.UpdatedDate = DateTime.Now;
                mp.CreatedDate = DateTime.Now;
                string connectionString = MyConfig.getConnection("myconstring");
                PowerService ps = new PowerService(new BPM.Foundation.PWDB.PWDBDataContext(connectionString));
                var createdUser = ps.getUser(null, mp.CreatedBy);
                var updatedUser = ps.getUser(null, mp.UpdatedBy);
                if (createdUser != null)
                    mp.CreatedUser = createdUser.firstName;
                if (updatedUser != null)
                    mp.UpdatedUser = updatedUser.firstName;

                var po = new ProdPlanOrderEntity();
                po.Id = mp.Id;
                po.CreatedBy = mp.CreatedBy;
                po.CreatedDate = mp.CreatedDate;
                po.UpdatedBy = mp.UpdatedBy;
                po.UpdatedDate = mp.UpdatedDate;
                string poNo = MstCodeRuleBs.GetCurrentOrderCode("ProductPlanOrder");
                if (string.IsNullOrEmpty(poNo))
                    return null;
                po.PoNo = poNo;
                mp.ProdPoNo = poNo;
                po.SappItemId = mp.SalesAppItemId;
                po.ProductId = mp.ProductId;
                po.BlueprintId = mp.BlueprintId;
                po.BomId = mp.BomId;
                po.Qty = mp.Qty;
                po.DeliveryDate = mp.RequiredDate;
                po.IsActive = mp.IsActive;
                if (!string.IsNullOrEmpty(mp.InvType))
                    po.InvType = mp.InvType;
                po.Remark = mp.Remark;
                po.Status = mp.Status;
                po.ProductCode = mp.ProductCode;
                po.ProductName = mp.ProductName;
                po.StartTime = mp.StartTime;
                po.SappItemId = mp.SalesAppNo;
                po.ContractModel = mp.ContractModel;
                if (ProdPlanOrderBs.InsertProdPlanOrderWithSoNo(po))
                    return mp;
                else return null;
            }
            catch (Exception ex)
            {
                throw new FaultException<ProcessExecutionFault>
                    (new ProcessExecutionFault(), ex.Message);
            }
        }

        public ProdMaintainPo UpdateMaintainPo(ProdMaintainPo mp)
        {
            try
            {
                if (mp == null)
                    return null;
                if (string.IsNullOrEmpty(mp.Id))
                    return null;
                var po = ProdPlanOrderBs.GetProdPlanOrder(new ProdPlanOrderEntity { Id = mp.Id });
                if (po == null)
                    return null;
                mp.UpdatedDate = DateTime.Now;
                string connectionString = MyConfig.getConnection("myconstring");
                PowerService ps = new PowerService(new BPM.Foundation.PWDB.PWDBDataContext(connectionString));
                var createdUser = ps.getUser(null, mp.CreatedBy);
                var updatedUser = ps.getUser(null, mp.UpdatedBy);
                if (createdUser != null)
                    mp.CreatedUser = createdUser.firstName;
                if (updatedUser != null)
                    mp.UpdatedUser = updatedUser.firstName;

                po.UpdatedBy = mp.UpdatedBy;
                po.UpdatedDate = DateTime.Now;
                po.PoNo = mp.ProdPoNo;
                po.SappItemId = mp.SalesAppItemId;
                po.ProductId = mp.ProductId;
                po.BlueprintId = mp.BlueprintId;
                po.BomId = mp.BomId;
                po.Qty = mp.Qty;
                po.DeliveryDate = mp.RequiredDate;
                po.IsActive = mp.IsActive;
                if (!string.IsNullOrEmpty(mp.InvType))
                    po.InvType = mp.InvType;
                po.Remark = mp.Remark;
                po.Status = mp.Status;
                po.ProductCode = mp.ProductCode;
                po.ProductName = mp.ProductName;
                po.StartTime = mp.StartTime;
                po.SappItemId = mp.SalesAppNo;
                po.ContractModel = mp.ContractModel;

                if (ProdPlanOrderBs.UpdateProdPlanOrderWithSoNo(po))
                    return mp;
                else return null;
            }
            catch (Exception ex)
            {
                throw new FaultException<ProcessExecutionFault>
                    (new ProcessExecutionFault(), ex.Message);
            }
        }

        public int? DelMaintainPo(ProdMaintainPo mp)
        {
            if (mp == null)
                return 1;
            if (string.IsNullOrEmpty(mp.Id))
                return 2;
            var po = ProdPlanOrderBs.GetProdPlanOrder(new ProdPlanOrderEntity { Id = mp.Id });
            if (po == null)
                return 3;
            if (ProdPlanOrderBs.DeleteProdPlanOrder(po))
                return null;
            else return -1;
        }


        public ProdMaintainPo GetMaintainPoByKey(string PoId)
        {
            try
            {
                if (string.IsNullOrEmpty(PoId))
                    return null;
                var po = ProdPlanOrderBs.GetProdPlanOrder(new ProdPlanOrderEntity { Id = PoId });
                if (po == null)
                    return null;
                string connectionString = MyConfig.getConnection("myconstring");
                PowerService ps = new PowerService(new BPM.Foundation.PWDB.PWDBDataContext(connectionString));
                ProdMaintainPo mpo = new ProdMaintainPo();
                mpo.Id = po.Id;
                mpo.CreatedBy = po.CreatedBy;
                if (!string.IsNullOrEmpty(po.CreatedBy))
                {
                    var createdUser = ps.getUser(null, po.CreatedBy);
                    mpo.CreatedUser = createdUser.firstName;
                }
                mpo.CreatedDate = po.CreatedDate;
                mpo.UpdatedBy = po.UpdatedBy;
                if (!string.IsNullOrEmpty(po.UpdatedBy))
                {
                    var updatedUser = ps.getUser(null, po.UpdatedBy);
                    mpo.UpdatedUser = updatedUser.firstName;
                }
                mpo.UpdatedDate = po.UpdatedDate;
                mpo.ProdPoNo = po.PoNo;
                mpo.Qty = po.Qty;
                mpo.RequiredDate = po.DeliveryDate;
                mpo.ProductId = po.ProductId;
                if (!string.IsNullOrEmpty(po.ProductId))
                {
                    var product = MstProductBs.GetMstProduct(new MstProductEntity { ProductId = po.ProductId });
                    if (product != null && product.ProductName != null)
                    {
                        mpo.ProductName = product.ProductName;
                        mpo.ProductCode = product.ProductCode;
                    }
                }
                mpo.BlueprintId = po.BlueprintId;
                mpo.BomId = po.BomId;
                mpo.SalesAppItemId = po.SappItemId;
                mpo.SalesAppNo = po.SappItemId;
                mpo.SalesAppId = po.SappItemId;
                //if (!string.IsNullOrEmpty(po.SappItemId))
                //{
                //    var salesAppItem = SalesProdPlanApplicationItemBs.GetSalesProdPlanApplicationItem(new SalesProdPlanApplicationItemEntity { ApplicationItemId = po.SappItemId });
                //    if (salesAppItem != null)
                //    {
                //        mpo.ContractModel = salesAppItem.ProductSpecOut;
                //        var salesApp = SalesProdPlanApplicationBs.GetSalesAppByKey(salesAppItem.ApplicationId);
                //        if (salesApp != null)
                //        {
                //            mpo.SalesAppId = salesApp.ApplicationId;
                //            mpo.SalesAppNo = salesApp.ApplicationCode;
                //        }
                //    }
                //}
                mpo.InvType = po.InvType;
                mpo.IsActive = po.IsActive;
                mpo.Remark = po.Remark;
                mpo.Status = po.Status;
                mpo.ProductName = po.ProductName;
                mpo.ProductCode = po.ProductCode;
                mpo.StartTime = po.StartTime;
                mpo.IsMark = po.IsMark;
                return mpo;
            }
            catch (Exception ex)
            {
                throw new FaultException<ProcessExecutionFault>
                    (new ProcessExecutionFault(), ex.Message);
            }
        }


        public ProdMaintainPo GetMaintainPoByCondition(ProdPlanOrderEntity PoCondition)
        {
            try
            {
                if (PoCondition == null) return null;
                var po = ProdPlanOrderBs.GetProdPlanOrder(new ProdPlanOrderEntity { Id = PoCondition.Id, PoNo = PoCondition.PoNo });
                if (po == null)
                    return null;
                string connectionString = MyConfig.getConnection("myconstring");
                PowerService ps = new PowerService(new BPM.Foundation.PWDB.PWDBDataContext(connectionString));
                ProdMaintainPo mpo = new ProdMaintainPo();
                mpo.Id = po.Id;
                mpo.CreatedBy = po.CreatedBy;
                if (!string.IsNullOrEmpty(po.CreatedBy))
                {
                    var createdUser = ps.getUser(null, po.CreatedBy);
                    mpo.CreatedUser = createdUser.firstName;
                }
                mpo.CreatedDate = po.CreatedDate;
                mpo.UpdatedBy = po.UpdatedBy;
                if (!string.IsNullOrEmpty(po.UpdatedBy))
                {
                    var updatedUser = ps.getUser(null, po.UpdatedBy);
                    mpo.UpdatedUser = updatedUser.firstName;
                }
                mpo.UpdatedDate = po.UpdatedDate;
                mpo.ProdPoNo = po.PoNo;
                mpo.Qty = po.Qty;
                mpo.RequiredDate = po.DeliveryDate;
                mpo.ProductId = po.ProductId;
                if (!string.IsNullOrEmpty(po.ProductId))
                {
                    var product = MstProductBs.GetMstProduct(new MstProductEntity { ProductId = po.ProductId });
                    if (product != null && product.ProductName != null)
                    {
                        mpo.ProductName = product.ProductName;
                        mpo.ProductCode = product.ProductCode;
                    }
                }
                mpo.BlueprintId = po.BlueprintId;
                mpo.BomId = po.BomId;
                mpo.SalesAppItemId = po.SappItemId;
                mpo.SalesAppNo = po.SappItemId;
                mpo.SalesAppId = po.SappItemId;
                //if (!string.IsNullOrEmpty(po.SappItemId))
                //{
                //    var salesAppItem = SalesProdPlanApplicationItemBs.GetSalesProdPlanApplicationItem(new SalesProdPlanApplicationItemEntity { ApplicationItemId = po.SappItemId });
                //    if (salesAppItem != null)
                //    {
                //        mpo.ContractModel = salesAppItem.ProductSpecOut;
                //        var salesApp = SalesProdPlanApplicationBs.GetSalesAppByKey(salesAppItem.ApplicationId);
                //        if (salesApp != null)
                //        {
                //            mpo.SalesAppId = salesApp.ApplicationId;
                //            mpo.SalesAppNo = salesApp.ApplicationCode;
                //        }
                //    }
                //}
                mpo.InvType = po.InvType;
                mpo.IsActive = po.IsActive;
                mpo.Remark = po.Remark;
                mpo.Status = po.Status;
                mpo.ProductName = po.ProductName;
                mpo.ProductCode = po.ProductCode;
                mpo.StartTime = po.StartTime;
                mpo.IsMark = po.IsMark;
                return mpo;
            }
            catch (Exception ex)
            {
                throw new FaultException<ProcessExecutionFault>
                    (new ProcessExecutionFault(), ex.Message);
            }
        }


        public List<ProdMaintainPo> GetMaintainPoAllByCondition(ProdPoQueryCondition con)
        {

            int pageIndex = 1;
            int pageSize = 50;
            string condition = "";
            if (con != null)
            {
                if (con.txtPageIndex != 0)
                    pageIndex = con.txtPageIndex;
                if (con.txtPageSize != 0)
                    pageSize = con.txtPageSize;

                if (!string.IsNullOrEmpty(con.PoNo))
                    condition += " and po.po_No like'%" + con.PoNo + "%'";
                if (!string.IsNullOrEmpty(con.ProductName))
                    condition += " and po.PRODUCT_NAME like '%" + con.ProductName + "%'";
                if (!string.IsNullOrEmpty(con.ProductCode))
                    condition += " and po.PRODUCT_CODE like '%" + con.ProductCode + "%'";
                if (!string.IsNullOrEmpty(con.ContractModel))
                    condition += " and po.CONTRACT_MODEL like '%" + con.ContractModel + "%'";
                if (!string.IsNullOrEmpty(con.Status))
                    condition += " and po.Status='" + con.Status + "'";
            }
            DataSet ds = ProdPlanOrderBs.GetAllDsByCondition(pageIndex, pageSize, condition);
            List<ProdMaintainPo> result = new List<ProdMaintainPo>();
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                ProdMaintainPo po = new ProdMaintainPo();
                po.Id = dr["ID"].ToString();
                po.CreatedBy = dr["CREATED_BY"].ToString();
                po.CreatedUser = dr["CREATED_USER"].ToString();
                if (dr["CREATED_DATE"] != DBNull.Value)
                    po.CreatedDate = (DateTime)dr["CREATED_DATE"];
                po.UpdatedBy = dr["UPDATED_BY"].ToString();
                po.UpdatedUser = dr["UPDATED_USER"].ToString();
                if (dr["UPDATED_DATE"] != DBNull.Value)
                    po.UpdatedDate = (DateTime)dr["UPDATED_DATE"];
                if (dr["IS_ACTIVE"] != null && dr["IS_ACTIVE"].ToString() != "")
                    po.IsActive = (int)dr["IS_ACTIVE"];
                po.ProdPoNo = dr["PO_NO"].ToString();
                po.Qty = (decimal)dr["QTY"];
                if (dr["DELIVERY_DATE"] != DBNull.Value)
                    po.RequiredDate = (DateTime)dr["DELIVERY_DATE"];
                po.ProductId = dr["PRODUCT_ID"].ToString();
                po.BlueprintId = dr["BLUEPRINT_ID"].ToString();
                po.ProductName = dr["PRODUCT_NAME"].ToString();
                po.ProductCode = dr["PRODUCT_CODE"].ToString();
                po.BomId = dr["BOM_ID"].ToString();
                po.ContractModel = dr["CONTRACT_MODEL"].ToString();
                po.SalesAppId = dr["SALES_APP_ID"].ToString();
                po.SalesAppNo = dr["SALES_APP_NO"].ToString();
                po.SalesAppItemId = dr["SAPP_ITEM_ID"].ToString();
                po.SalesAppNo = dr["SAPP_ITEM_ID"].ToString();
                po.InvType = dr["INV_TYPE"].ToString();
                po.InvLocation = dr["LOCATION_CODE"].ToString();
                po.Remark = dr["REMARK"].ToString();
                po.Status = dr["STATUS"].ToString();
                po.ProductName = dr["PRODUCT_NAME"].ToString();
                po.ProductCode = dr["PRODUCT_CODE"].ToString();
                po.IsMark = string.IsNullOrEmpty(dr["IS_MARK"].ToString()) ? 0 : Convert.ToInt32(dr["IS_MARK"]);
                po.StartTime = string.IsNullOrEmpty(dr["START_TIME"].ToString()) ? DateTime.Now : Convert.ToDateTime(dr["START_TIME"]);
                if (dr["cnt"] != null && dr["cnt"].ToString() != "")
                    po.Cnt = (int)dr["cnt"];
                result.Add(po);
            }
            return result;
        }

        public DTODataTable GetMtrlReqPo()
        {
            DTODataTable output = new DTODataTable();
            try
            {
                DataTable ds = ProdPlanOrderBs.GetPOMtrlReq();
                output.result = ds;

            }
            catch (Exception ex)
            {
                output.ErrorCode = "GetMtrlReqPo";
                output.ErrorMessage = ex.Message;
            }
            return output;
        }

        public DTODataTable GetMtrlHoldByPo()
        {
            DTODataTable output = new DTODataTable();
            try
            {
                DataTable ds = ProdPlanOrderBs.GetMtrlHoldByPo();
                output.result = ds;
            }
            catch (Exception ex)
            {
                output.ErrorCode = "GetMtrlHoldByPo";
                output.ErrorMessage = ex.Message;
            }
            return output;
        }


        //public int? AddPoTaskuser(ProdPoTaskuserEntity tu)
        //{
        //    if (tu == null)
        //        return 1;
        //    if (ProdPoTaskuserBs.InsertProdPoTaskuser(tu))
        //        return null;
        //    else return -1;
        //}

        //public int? UpdatePoTaskuser(ProdPoTaskuserEntity tu)
        //{
        //    if (tu == null)
        //        return 1;
        //    if (ProdPoTaskuserBs.UpdateProdPoTaskuser(tu))
        //        return null;
        //    else return -1;
        //}

        //public int? DelPoTaskuser(ProdPoTaskuserEntity tu)
        //{
        //    if (tu == null)
        //        return 1;
        //    if (ProdPoTaskuserBs.DeleteProdPoTaskuser(tu))
        //        return null;
        //    else return -1;
        //}

        //public List<ProdPoTaskuserEntity> GetPoTaskuserAllList(string poId, string bomItemId, string bomTechnicItemId)
        //{
        //    if (string.IsNullOrEmpty(poId)
        //        || string.IsNullOrEmpty(bomItemId) || string.IsNullOrEmpty(bomTechnicItemId))
        //        return null;
        //    return ProdPoTaskuserBs.GetProdPoTaskuserAllList(poId, bomItemId, bomTechnicItemId);
        //}


        //public int? SavePoTaskuser(ProdPoTaskuserEntity tu)
        //{
        //    if (tu == null)
        //        return 1;
        //    var cur = ProdPoTaskuserBs.GetProdPoTaskuser(new ProdPoTaskuserEntity { Id = tu.Id });
        //    if (cur == null)
        //    {
        //        if (ProdPoTaskuserBs.InsertProdPoTaskuser(tu))
        //            return null;
        //        else return -1;
        //    }
        //    else
        //    {
        //        var update = new ProdPoTaskuserEntity();
        //        update.ProdPoId = tu.ProdPoId;
        //        update.BomItemId = tu.BomItemId;
        //        update.BomTechnicItemId = tu.BomTechnicItemId;
        //        update.UserNo = tu.UserNo;
        //        update.UserName = tu.UserName;
        //        update.TimeFrom = tu.TimeFrom;
        //        update.TimeTo = tu.TimeTo;
        //        update.Qty = tu.Qty;
        //        if (ProdPoTaskuserBs.UpdateProdPoTaskuser(tu))
        //            return null;
        //        else return -1;
        //    }
        //}

        //public int? SavePoTaskusers(List<ProdPoTaskuserEntity> tus)
        //{
        //    if (tus == null)
        //        return 1;
        //    if (tus.Count == 0)
        //        return 2;
        //    var cur = ProdPoTaskuserBs.GetProdPoTaskuserAllListByCondition(tus[0].ProdPoId, tus[0].BomTechnicItemId);
        //    List<ProdPoTaskuserEntity> adds = new List<ProdPoTaskuserEntity>();
        //    List<ProdPoTaskuserEntity> updates = new List<ProdPoTaskuserEntity>();
        //    List<ProdPoTaskuserEntity> dels = new List<ProdPoTaskuserEntity>();
        //    if (cur == null || cur.Count == 0)
        //    {
        //        if (ProdPoTaskuserBs.InsertProdPoTaskuser(tus))
        //            return null;
        //        else return -1;
        //    }
        //    else
        //    {
        //        foreach (var tu in tus)
        //        {
        //            var u = cur.Find(a => a.Id == tu.Id);
        //            if (u != null)//更新
        //            {
        //                u.ProdPoId = tu.ProdPoId;
        //                u.BomItemId = tu.BomItemId;
        //                u.BomTechnicItemId = tu.BomTechnicItemId;
        //                u.UserNo = tu.UserNo;
        //                u.UserName = tu.UserName;
        //                u.TimeFrom = tu.TimeFrom;
        //                u.TimeTo = tu.TimeTo;
        //                tu.Qty = tu.Qty;
        //                updates.Add(u);
        //                cur.Remove(u);
        //            }
        //            else
        //            {
        //                adds.Add(tu);
        //            }
        //        }
        //        dels = cur;
        //        if (ProdPoTaskuserBs.Save(adds, updates, dels))
        //            return null;
        //        else return -1;
        //    }


        //}

        /// <summary>根据生产计划，生成工单、采购单、工单任务
        /// </summary>
        /// <param name="bomItems"></param>
        /// <returns></returns>
        public int? ProdPoToWo(string userNo, ProdMaintainPo mpo, DataSet bomItems)
        {
            if (bomItems == null)
                return 1;
            if (bomItems.Tables[0].Rows.Count == 0)
                return 2;

            ProdPlanOrderEntity po = ProdPlanOrderBs.GetProdPlanOrder(new ProdPlanOrderEntity { Id = mpo.Id });

            if (po.InvType.Equals("按订单存放"))////////////////////////////////////////////////////获取库位，未完成
            {
                po.LocationCode = "";
            }
            else if (po.InvType.Equals("按物料存放"))
            {
            }

            List<ProdWoEntity> wos = new List<ProdWoEntity>();
            List<ProdWoTaskEntity> wts = new List<ProdWoTaskEntity>();
            foreach (DataRow bomItem in bomItems.Tables[0].Rows)
            {
                if (bomItem["ITEM_TYPE"].ToString().Equals("PDTYPE01") || bomItem["ITEM_TYPE"].ToString().Equals("PDTYPE04"))
                {
                    var bomTechnic = BomTechnicBs.GetBomTechnic(new BomTechnicEntity { ProductId = bomItem["PRODUCT_ID"].ToString(), IsActive = 1, Status = Common.WfStatus.WFS30.ToString() });
                    if (bomTechnic == null)
                        return null;

                    //工单
                    ProdWoEntity wo = new ProdWoEntity();
                    wo.Id = Guid.NewGuid().ToString();
                    wo.IsActive = 1;
                    wo.CreatedBy = userNo;
                    wo.CreatedDate = DateTime.Now;
                    wo.UpdatedBy = userNo;
                    wo.UpdatedDate = DateTime.Now;
                    wo.Status = Common.WoStatus.WOS_Daft.ToString();
                    string woNo = MstCodeRuleBs.GetCurrentOrderCode("WorkOrder");
                    wo.WoNo = woNo;
                    wo.PoId = po.Id;
                    wo.BomItemId = bomItem["ID"].ToString();
                    wo.BomTechnicId = bomTechnic.Id;
                    wo.ProductId = bomItem["PRODUCT_ID"].ToString();
                    wo.Qty = po.Qty * (Convert.ToDecimal(bomItem["UNIT_DOSE"]));
                    //用于计算可用量
                    wo.StorageQty = 0;
                    // wo.ProductedQty = 0;
                    // wo.PurchaaseQty = 0;
                    wos.Add(wo);

                    var bomTechItems = BomTechnicItemBs.GetListBomTechnicItemAllListByTechId(bomTechnic.Id);
                    foreach (var ti in bomTechItems)
                    {
                        //var poTaskusers = ProdPoTaskuserBs.GetProdPoTaskuserAllListByCondition(po.PlanOrderId, ti.Id);
                        //foreach (var poTaskuser in poTaskusers)
                        //{
                        //    ProdWoTaskEntity wt = new ProdWoTaskEntity();
                        //    wt.Id = Guid.NewGuid().ToString();
                        //    wt.WoId = wo.Id;
                        //    wt.TechnicId = ti.TechnicId;
                        //    wt.UserNo = poTaskuser.UserNo;
                        //    wt.RequiredQty = poTaskuser.Qty;
                        //    wt.RequiredTimeFrom = poTaskuser.TimeFrom;
                        //    wt.RequiredTimeTo = poTaskuser.TimeTo;
                        //    wt.ReportedQty = 0;
                        //    wt.Status = Common.WfStatus.草稿.ToString();
                        //    wts.Add(wt);

                        //}
                    }

                }

            }
            if (ProdPlanOrderBs.PoToWo(po, wos, wts))
                return null;
            else return -1;
        }


        public List<ProdMaintainWo> CreateWoFromPo(string userNo, ProdMaintainPo mpo)
        {
            List<ProdWoEntity> woList = ProdPlanOrderBs.CreateWo(userNo, mpo);
            if (woList == null) return null;
            List<ProdMaintainWo> woOutput = new List<ProdMaintainWo>();
            ProdMaintainWo output;
            string connectionString = MyConfig.getConnection("myconstring");
            PowerService ps = new PowerService(new BPM.Foundation.PWDB.PWDBDataContext(connectionString));
            PW_User createdUser = ps.getUser(null, userNo);
            foreach (ProdWoEntity wo in woList)
            {
                output = Common.CommonFunction.CopyEntityToServiceOutPut<ProdMaintainWo, ProdWoEntity>(wo);
                if (output != null)
                {
                    output.ContractModel = mpo.ContractModel;
                    output.CreatedUser = createdUser.firstName;
                    output.PoNo = mpo.ProdPoNo;
                    output.PoId = mpo.Id;
                    output.RequiredDate = wo.ReqDate;
                    output.PlanStartDate = wo.PlanStartDate;
                    output.UpdatedUser = createdUser.firstName;
                    output.WoQty = wo.Qty;
                    woOutput.Add(output);
                }
            }
            return woOutput;

        }


        /// <summary>根据ID，查询工单
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ProdWoEntity GetProdWoByKey(string id)
        {
            if (string.IsNullOrEmpty(id))
                return null;
            var wo = ProdWoBs.GetProdWo(new ProdWoEntity { Id = id });
            return wo;
        }

        /// <summary>根据ID，查询工单
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ProdMaintainWo GetProdMaintainWoByKey(string id)
        {
            if (string.IsNullOrEmpty(id))
                return null;
            string connectionString = MyConfig.getConnection("myconstring");
            PowerService ps = new PowerService(new BPM.Foundation.PWDB.PWDBDataContext(connectionString));

            var wo = ProdWoBs.GetProdWo(new ProdWoEntity { Id = id });
            ProdMaintainWo mwo = new ProdMaintainWo();
            mwo.Id = wo.Id;
            var createdUser = ps.getUser(null, wo.CreatedBy);
            var updatedUser = ps.getUser(null, wo.UpdatedBy);
            if (createdUser != null)
            {
                mwo.CreatedBy = createdUser.userNo;
                mwo.CreatedUser = createdUser.firstName;
            }
            mwo.CreatedDate = DateTime.Now;
            if (updatedUser != null)
            {
                mwo.UpdatedBy = updatedUser.userNo;
                mwo.UpdatedUser = updatedUser.firstName;
            }
            mwo.UpdatedDate = DateTime.Now;
            mwo.IsActive = wo.IsActive;
            mwo.WoNo = wo.WoNo;
            var po = ProdPlanOrderBs.GetProdPlanOrder(new ProdPlanOrderEntity { Id = wo.PoId });
            if (po == null)
                return null;
            mwo.PoNo = po.PoNo;
            mwo.ContractModel = po.ContractModel;
            mwo.BomItemId = wo.BomItemId;
            mwo.BomTechnicId = wo.BomTechnicId;
            mwo.ProductId = wo.ProductId;
            var product = MstProductBs.GetMstProduct(new MstProductEntity { ProductId = wo.ProductId });
            if (product == null)
                return null;
            mwo.ProductName = product.ProductName;
            mwo.ProductCode = product.ProductCode;
            mwo.BlueprintId = wo.BlueprintId;
            mwo.WoQty = wo.Qty;
            mwo.Unit = wo.Unit;
            mwo.Type = wo.Type;
            mwo.RequiredDate = wo.ReqDate;
            mwo.Status = wo.Status;
            return mwo;
        }

        /// <summary>根据条件，查询工单
        /// 
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public DataSet GetProdWoAllDsByCondition(ProdWoQueryCondition queryCondition)
        {
            int pageIndex = 1;
            int pageCount = 50;
            if (queryCondition.txtPageIndex != 0)
                pageIndex = queryCondition.txtPageIndex;
            if (queryCondition.txtPageSize != 0)
                pageCount = queryCondition.txtPageSize;
            string condition = "";

            if (!string.IsNullOrEmpty(queryCondition.PoNo))
            {
                condition += " and po.po_no='" + queryCondition.PoNo + "'";
            }
            if (!string.IsNullOrEmpty(queryCondition.WoNo))
            {
                condition += " and wo.wo_no='" + queryCondition.WoNo + "'";
            }
            if (!string.IsNullOrEmpty(queryCondition.ContractModel))
            {
                condition += " and po.contract_model='" + queryCondition.ContractModel + "'";
            }
            if (!string.IsNullOrEmpty(queryCondition.ProductName))
            {
                condition += " and wo.product_name='" + queryCondition.ProductName + "'";
            }
            if (!string.IsNullOrEmpty(queryCondition.ProductCode))
            {
                condition += " and wo.product_code='" + queryCondition.ProductCode + "'";
            }
            if (!string.IsNullOrEmpty(queryCondition.Status))
            {
                condition += " and wo.status='" + queryCondition.Status + "'";
            }
            return ProdWoBs.GetAllDsByCondition(pageIndex, pageCount, condition);
        }

        /// <summary>
        /// 根据用户，查询执行中的工单任务
        /// </summary>
        /// <returns></returns>
        public DataSet GetProdWoTaskAllDsByUserNo(string userNo)
        {
            if (string.IsNullOrEmpty(userNo))
                return null;
            string sql = @"select wt.*,wo.WO_NO,po.CONTRACT_MODEL,mp.PRODUCT_CODE,mp.PRODUCT_NAME,pt.TECHNIC_NAME
from PROD_WO_TASK wt
left join PROD_WO wo on wt.WO_ID=wo.ID
left join PROD_PLAN_ORDER po on wo.PO_ID=po.Id
left join MST_PRODUCT mp on wo.PRODUCT_ID=mp.PRODUCT_ID
left join PROD_TECHNIC pt on wt.TECHNIC_ID=pt.TECHNIC_ID
where wt.USER_NO='{0}' and wt.status!='删除' and (wt.status='{1}' or wt.sequence=1)";
            sql = string.Format(sql, userNo, Common.WfStatus.WFS20.ToString());
            return ProdWoTaskBs.GetWoTaskAllDsBySql(sql);
        }

        /// <summary>
        /// 根据工单，查询非删除状态工单任务
        /// </summary>
        /// <returns>wt.*,wo.WO_NO,po.CONTRACT_MODEL,mp.PRODUCT_CODE,mp.PRODUCT_NAME,pt.TECHNIC_NAME</returns>
        public DataSet GetProdWoTaskAllDsByWoId(string woId)
        {
            if (string.IsNullOrEmpty(woId))
                return null;
            string sql = @"select wt.*,wo.WO_NO,po.CONTRACT_MODEL,mp.PRODUCT_CODE,mp.PRODUCT_NAME,pt.TECHNIC_NAME,u.firstName as USER_NAME
from PROD_WO_TASK wt
left join PROD_WO wo on wt.WO_ID=wo.ID
left join PROD_PLAN_ORDER po on wo.PO_ID=po.Id
left join MST_PRODUCT mp on wo.PRODUCT_ID=mp.PRODUCT_ID
left join PROD_TECHNIC pt on wt.TECHNIC_ID=pt.TECHNIC_ID
left join BPMDB.dbo.PW_USER u on wt.USER_NO=u.userNo
where wt.status!='{0}' and wt.wo_id='{1}'
order by wt.sequence";
            sql = string.Format(sql, Common.WfStatus.WFS40.ToString(), woId);
            return ProdWoTaskBs.GetWoTaskAllDsBySql(sql);
        }

        /// <summary>
        /// 根据用户，查询非删除状态工单任务
        /// </summary>
        /// <param name="userNo"></param>
        /// <returns></returns>
        public DataSet GetProdWoProcessingTaskAllDsByUserNo(string userNo)
        {
            if (string.IsNullOrEmpty(userNo))
                return null;
            string sql = @"select wt.*,wo.WO_NO,po.CONTRACT_MODEL,mp.PRODUCT_CODE,mp.PRODUCT_NAME,pt.TECHNIC_NAME,u.firstName as USER_NAME
from PROD_WO_TASK wt
left join PROD_WO wo on wt.WO_ID=wo.ID
left join PROD_PLAN_ORDER po on wo.PO_ID=po.Id
left join MST_PRODUCT mp on wo.PRODUCT_ID=mp.PRODUCT_ID
left join PROD_TECHNIC pt on wt.TECHNIC_ID=pt.TECHNIC_ID
left join BPMDB.dbo.PW_USER u on wt.USER_NO=u.userNo
where wt.status=='{0}' and wt.USER_NO='{1}'
order by wt.sequence";
            sql = string.Format(sql, Common.WfStatus.WFS20.ToString(), userNo);
            return ProdWoTaskBs.GetWoTaskAllDsBySql(sql);
        }

        /// <summary>
        /// 查询非删除状态工单任务
        /// </summary>
        /// <returns>wt.*,wo.WO_NO,po.CONTRACT_MODEL,mp.PRODUCT_CODE,mp.PRODUCT_NAME,pt.TECHNIC_NAME,
        ///ma.PRODUCT_NAME,bim.PICKING_MODEL,bim.NET_SIZE,bim.GROSS_SIZE,bim.UNIT_WEIGHT</returns>
        public DataSet GetProdWoMaterialTaskAllDs()
        {
            string sql = @"select wt.*,wo.WO_NO,po.CONTRACT_MODEL,mp.PRODUCT_CODE,mp.PRODUCT_NAME,pt.TECHNIC_NAME,
ma.PRODUCT_NAME as MATERIAL_NAME,bi.UNIT_DOSE,bim.MATERIAL_ID,bim.PICKING_MODEL,bim.NET_SIZE,bim.GROSS_SIZE,bim.UNIT_WEIGHT,bim.MANUFACTURING_TYPE,bim.REMARK
from PROD_WO_TASK wt
left join PROD_WO wo on wt.WO_ID=wo.ID
left join PROD_PLAN_ORDER po on wo.PO_ID=po.Id
left join MST_PRODUCT mp on wo.PRODUCT_ID=mp.PRODUCT_ID
left join PROD_TECHNIC pt on wt.TECHNIC_ID=pt.TECHNIC_ID
left join BOM_ITEM bi on wo.BOM_ITEM_ID=bi.ID
left join BOM_ITEM_MATERIAL bim on bi.ID=bim.BOM_ITEM_ID
left join MST_PRODUCT ma on bim.MATERIAL_ID=ma.PRODUCT_ID
where wt.status!='{0}'";
            sql = string.Format(sql, Common.WfStatus.WFS40.ToString());
            return ProdWoTaskBs.GetWoTaskAllDsBySql(sql);
        }

        public DataSet GetProdWoMaterialTaskAllDsByCondition(ProdWoTaskCondition con)
        {
            string sql = @"select wt.*,wo.WO_NO,po.CONTRACT_MODEL,mp.PRODUCT_CODE,mp.PRODUCT_NAME,pt.TECHNIC_NAME,
ma.PRODUCT_NAME as MATERIAL_NAME,bi.UNIT_DOSE,bim.MATERIAL_ID,bim.PICKING_MODEL,bim.NET_SIZE,bim.GROSS_SIZE,bim.UNIT_WEIGHT,bim.MANUFACTURING_TYPE,bim.REMARK
from PROD_WO_TASK wt
left join PROD_WO wo on wt.WO_ID=wo.ID
left join PROD_PLAN_ORDER po on wo.PO_ID=po.Id
left join MST_PRODUCT mp on wo.PRODUCT_ID=mp.PRODUCT_ID
left join PROD_TECHNIC pt on wt.TECHNIC_ID=pt.TECHNIC_ID
left join BOM_ITEM bi on wo.BOM_ITEM_ID=bi.ID
left join BOM_ITEM_MATERIAL bim on bi.ID=bim.BOM_ITEM_ID
left join MST_PRODUCT ma on bim.MATERIAL_ID=ma.PRODUCT_ID
where wt.status!='{0}'";
            sql = string.Format(sql, Common.WfStatus.WFS40.ToString());
            if (!string.IsNullOrEmpty(con.WoNo))
            {
                sql += " and wo.wo_no='" + con.WoNo + "'";
            }
            if (!string.IsNullOrEmpty(con.ContractModel))
            {
                sql += " and po.contract_model like '%" + con.ContractModel + "%'";
            }
            if (!string.IsNullOrEmpty(con.TechnicName))
            {
                sql += " and pt.technic_name='" + con.TechnicName + "'";
            }
            if (con.RequiredDate != null && con.RequiredDate != new DateTime(1, 1, 1))
            {
                sql += " and wt.required_time_from<='" + con.RequiredDate.ToString("yyyy-MM-dd HH:mm:ss") + "'";
                sql += " and wt.required_time_to>='" + con.RequiredDate.ToString("yyyy-MM-dd HH:mm:ss") + "'";
            }
            if (!string.IsNullOrEmpty(con.ProductId))
            {
                sql += " and wo.product_id='" + con.ProductId + "'";
            }
            else if (!string.IsNullOrEmpty(con.ProductName))
            {
                sql += " and mp.product_name like '%" + con.ProductName + "%'";
            }
            if (!string.IsNullOrEmpty(con.UserNo))
            {
                sql += " and wt.user_no='" + con.UserNo + "'";
            }
            if (!string.IsNullOrEmpty(con.WoStatus))
            {
                sql += " and wo.status='" + con.WoStatus + "'";
            }
            return ProdWoTaskBs.GetWoTaskAllDsBySql(sql);
        }

        /// <summary>
        /// 根据工单任务，创建放料单
        /// </summary>
        /// <param name="ds">wt.*,wo.WO_NO,po.CONTRACT_MODEL,mp.PRODUCT_CODE,mp.PRODUCT_NAME,pt.TECHNIC_NAME,
        ///ma.PRODUCT_NAME,bim.PICKING_MODEL,bim.NET_SIZE,bim.GROSS_SIZE,bim.UNIT_WEIGHT</param>
        /// <returns></returns>
        public ProdWoPickEntity CreateProdWoPick(string userNo, DataSet ds)
        {
            if (string.IsNullOrEmpty(userNo))
                return null;
            if (ds == null)
                return null;
            if (ds.Tables[0].Rows.Count == 0)
                return null;
            var addPick = new ProdWoPickEntity();
            addPick.Id = Guid.NewGuid().ToString();
            addPick.CreatedBy = userNo;
            addPick.CreatedDate = DateTime.Now;
            addPick.UpdatedBy = userNo;
            addPick.UpdatedDate = DateTime.Now;
            addPick.IsActive = 1;
            addPick.PickNo = MstCodeRuleBs.GetCurrentOrderCode("PickingOrderCode");
            addPick.Status = Common.WfStatus.WFS10.ToString();

            var addPickItems = new List<ProdWoPickitemEntity>();
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                var pi = new ProdWoPickitemEntity();
                pi.Id = Guid.NewGuid().ToString();
                pi.PickId = addPick.Id;
                pi.WoTaskId = dr["ID"].ToString();
                pi.MaterialId = dr["MATERIAL_ID"].ToString();
                if (dr["REQUIRED_QTY"] != DBNull.Value)
                {
                    pi.Qty = Convert.ToDecimal(dr["REQUIRED_QTY"]);
                }
                if (dr["UNIT_DOSE"] != DBNull.Value)
                {
                    pi.UnitQty = Convert.ToDecimal(dr["UNIT_DOSE"]);
                }
                pi.PickingModel = dr["PICKING_MODEL"].ToString();
                pi.NetSize = dr["NET_SIZE"].ToString();
                pi.GrossSize = dr["GROSS_SIZE"].ToString();
                if (dr["UNIT_WEIGHT"] != DBNull.Value)
                {
                    pi.UnitWeight = Convert.ToDecimal(dr["UNIT_WEIGHT"]);
                }
                pi.Type = dr["MANUFACTURING_TYPE"].ToString();
                pi.Remark = dr["REMARK"].ToString();
                addPickItems.Add(pi);
            }
            if (ProdWoPickBs.CreateWoPick(addPick, addPickItems))
                return addPick;
            else return null;

        }

        public DataSet GetProdWoPickAllDsByCondition(ProdWoPickQueryCondition queryCondition)
        {
            int pageIndex = 1;
            int pageCount = 50;
            if (queryCondition.txtPageIndex != 0)
                pageIndex = queryCondition.txtPageIndex;
            if (queryCondition.txtPageSize != 0)
                pageCount = queryCondition.txtPageSize;
            string condition = "";
            if (queryCondition.IsActive != -1)
            {
                condition += " and wp.is_active='" + queryCondition.IsActive + "'";
            }
            if (!string.IsNullOrEmpty(queryCondition.PickNo))
            {
                condition += " and wp.pick_no='" + queryCondition.PickNo + "'";
            }
            if (!string.IsNullOrEmpty(queryCondition.Type))
            {
                condition += " and wp.type='" + queryCondition.Type + "'";
            }
            if (!string.IsNullOrEmpty(queryCondition.WhNo))
            {
                condition += " and wp.wh_no='" + queryCondition.WhNo + "'";
            }
            if (queryCondition.CreatedDateFrom != null && queryCondition.CreatedDateFrom != new DateTime(1, 1, 1))
            {
                condition += " and wp.created_date>='" + queryCondition.CreatedDateFrom.ToString("yyyy-MM-dd HH:mm:ss") + "'";
            }
            if (queryCondition.CreatedDateFrom != null && queryCondition.CreatedDateFrom != new DateTime(1, 1, 1))
            {
                condition += " and wp.created_date<='" + queryCondition.CreatedDateTo.ToString("yyyy-MM-dd HH:mm:ss") + "'";
            }
            if (!string.IsNullOrEmpty(queryCondition.MaterialId))
            {
                condition += " and wp.material_id='" + queryCondition.MaterialId + "'";
            }
            if (!string.IsNullOrEmpty(queryCondition.Status))
            {
                condition += " and wp.status='" + queryCondition.Status + "'";
            }
            return ProdWoTaskBs.GetAllDsByCondition(pageIndex, pageCount, condition);
        }

        public DataSet GetProdWoPickItemAllDsByPickId(string pickId)
        {
            if (string.IsNullOrEmpty(pickId))
                return null;
            string sql = @"select pi.*,mp.PRODUCT_NAME as MATERIAL_NAME,mp.PRODUCT_CODE as MATERIAL_CODE,
wo.WO_NO,p.PRODUCT_NAME,p.PRODUCT_CODE 
from PROD_WO_PICKITEM pi
left join MST_PRODUCT mp on pi.MATERIAL_ID=mp.PRODUCT_ID
left join PROD_WO_TASK wt on pi.WO_TASK_ID=wt.ID
left join PROD_WO wo on wt.WO_ID=wo.ID
left join MST_PRODUCT p on wo.PRODUCT_ID=p.PRODUCT_ID
where pi.PICK_ID='{0}'";
            sql = string.Format(sql, pickId);
            return ProdWoPickitemBs.GetWoPickItemAllDsBySql(sql);

        }

        /// <summary>
        /// 工单任务放料，保存放料数据
        /// 库存扣除数量
        /// 放料单状态变为“完成”,工单任务状态变为“完成”,下一工单任务状态转为“处理中”,并且报工
        /// </summary>
        /// <param name="pick"></param>
        /// <param name="pickItems"></param>
        /// <returns></returns>
        public int? Pick(ProdWoPickEntity pick, List<ProdWoPickitemEntity> pickItems)
        {
            if (pick == null)
                return 1;
            if (pickItems == null)
                return 2;
            if (pickItems.Count == 0)
                return 3;
            pick.Status = Common.WfStatus.WFS30.ToString();

            //var wts = new List<ProdWoTaskEntity>();
            //var wrs = new List<ProdWoReportEntity>();
            //foreach (var pickItem in pickItems)
            //{
            //    var wt = ProdWoTaskBs.GetProdWoTask(new ProdWoTaskEntity { Id = pickItem.WoTaskId });
            //    if (wt == null)
            //        return 4;
            //    if (pickItem.Qty + wt.ReportedQty != wt.RequiredQty)
            //    {
            //        wt.Status = Common.WfStatus.处理中.ToString();
            //    }
            //    else
            //    {
            //        wt.Status = Common.WfStatus.完成.ToString();
            //    }
            //    wt.RequiredQty += pickItem.Qty;
            //    wt.ReportedBy = pick.UpdatedBy;
            //    wt.ReportedDate = DateTime.Now;
            //    wts.Add(wt);

            //    //下一工序对应工单任务
            //    var nextWts = ProdWoTaskBs.GetProdWoTaskAllList(new ProdWoTaskEntity { WoId = wt.WoId, Sequence = wt.Sequence + 1, Status = Common.WfStatus.草稿.ToString() });
            //    if (nextWts != null)
            //    {
            //        wts.AddRange(nextWts);
            //    }

            //    var wr = new ProdWoReportEntity();
            //    wr.Id = Guid.NewGuid().ToString();
            //    wr.CreatedBy = pick.UpdatedBy;
            //    wr.CreatedDate = DateTime.Now;
            //    wr.UpdatedBy = pick.UpdatedBy;
            //    wr.UpdatedDate = DateTime.Now;
            //    wr.IsActive = 1;
            //    wr.WoTaskId = wt.Id;
            //    wr.Qty = pickItem.Qty;
            //    wrs.Add(wr);

            //}
            //if (ProdWoPickBs.Pick(pick, wts, wrs))
            //    return null;
            //else return -1;
            return null;
        }

        public int? AddTechnic(ProdTechnicEntity technic)
        {
            if (technic == null)
                return 1;
            technic.CreatedDate = DateTime.Now;
            technic.UpdatedDate = DateTime.Now;
            if (ProdTechnicBs.InsertProdTechnic(technic))
                return null;
            else return -1;
        }

        public int? UpdateTechnic(ProdTechnicEntity technic)
        {
            if (technic == null)
                return 1;
            technic.UpdatedDate = DateTime.Now;
            if (ProdTechnicBs.UpdateProdTechnic(technic))
                return null;
            else return -1;
        }

        public int? DelTechnic(ProdTechnicEntity technic)
        {
            if (technic == null)
                return 1;
            if (ProdTechnicBs.InsertProdTechnic(technic))
                return null;
            else return -1;
        }

        public ProdTechnicEntity GetTechnicByKey(string id)
        {
            if (string.IsNullOrEmpty(id))
                return null;
            return ProdTechnicBs.GetProdTechnic(new ProdTechnicEntity { TechnicId = id });
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="queryCondition"></param>
        /// <returns>t.*,u1.firstName as CREATED_USER,u2.firstName as UPDATED_USER </returns>
        public DataSet GetTechnicAllDsByCondition(ProdTechnicQueryCondition queryCondition)
        {
            string sql = @"select t.*,u1.firstName as CREATED_USER,u2.firstName as UPDATED_USER 
from prod_technic t
left join BPMDB.dbo.PW_User u1 on t.CREATED_BY=u1.userNo
left join BPMDB.dbo.PW_User u2 on t.UPDATED_BY=u2.userNo
where 1=1 ";
            //if (queryCondition.IsActive != -1)
            //{
            //    sql += " and t.is_active='" + queryCondition.IsActive + "'";
            //}
            if (!string.IsNullOrEmpty(queryCondition.Name))
            {
                sql += " and t.technic_name like '%" + queryCondition.Name + "%'";
            }
            if (!string.IsNullOrEmpty(queryCondition.Type))
            {
                sql += " and t.station_type='" + queryCondition.Type + "'";
            }

            return ProdTechnicBs.GetAllDsBySql(sql);
        }

        /// <summary>
        /// 报工
        /// 新增报工记录
        /// 更新工作任务表
        /// 下一任务状态改为“处理中”
        /// </summary>
        /// <param name="rw"></param>
        /// <returns></returns>
        //public int? ReportWork(ProdRwEntity rw)
        //{
        //    if (rw == null)
        //        return 1;
        //    rw.CreatedDate = DateTime.Now;

        //    var woTasks = new List<ProdWoTaskEntity>();
        //    var woTask = ProdWoTaskBs.GetProdWoTask(new ProdWoTaskEntity { Id = rw.WoTaskId });
        //    if (woTask == null)
        //        return 2;
        //    if (woTask.ReportedQty == null)
        //    {
        //        woTask.ReportedQty = rw.Qty;
        //    }
        //    else
        //    {
        //        woTask.ReportedQty += rw.Qty;
        //    }
        //    woTask.ReportedDate = DateTime.Now;
        //    woTask.ReportedBy = rw.CreatedBy;
        //    if (woTask.ReportedQty == woTask.RequiredQty)
        //    {
        //        woTask.Status = Common.WfStatus.完成.ToString();
        //    }
        //    woTasks.Add(woTask);

        //    var nextWoTask = ProdWoTaskBs.GetProdWoTask(new ProdWoTaskEntity { WoId = woTask.WoId, Sequence = woTask.Sequence + 1 });
        //    if (nextWoTask != null)
        //    {
        //        nextWoTask.Status = Common.WfStatus.处理中.ToString();
        //    }
        //    woTasks.Add(nextWoTask);

        //    if (ProdRwBs.ReportWork(rw, woTasks))
        //        return null;
        //    else return -1;
        //}

        /// <summary>
        /// 根据工单任务，查询需要领料的物料
        /// </summary>
        /// <param name="woTask"></param>
        /// <returns></returns>
        public List<ProdMaintainPickItem> GetPickItemAllListByWoTask(ProdWoTaskEntity woTask)
        {
            if (woTask == null)
                return null;
            var wo = ProdWoBs.GetProdWo(new ProdWoEntity { Id = woTask.WoId });
            if (wo == null)
                return null;
            var po = ProdPlanOrderBs.GetProdPlanOrder(new ProdPlanOrderEntity { Id = wo.PoId });
            if (po == null)
                return null;

            List<BomItemEntity> bomItems = new List<BomItemEntity>();
            if (wo.ProductId.Equals(po.ProductId))
            {
                //产品
                //成品时，产生的工单bomItemId被保存未bomMasterid
                //(临时，以后修改bom表，bomMaster顶级物料也存入bomItem)
                bomItems = BomItemBs.GetBomItemAllList(new BomItemEntity { BomMasterId = wo.BomItemId });
            }
            else
            {
                //半成品组装件
                bomItems = BomItemBs.GetBomItemAllList(new BomItemEntity { ParentId = wo.BomItemId });
            }
            if (bomItems.Count == 0)
                return null;

            var results = new List<ProdMaintainPickItem>();
            foreach (var bomItem in bomItems)
            {
                var r = new ProdMaintainPickItem();
                var product = MstProductBs.GetMstProduct(new MstProductEntity { ProductId = bomItem.ProductId });
                if (product == null)
                    return null;
                r.ProductId = bomItem.ProductId;
                r.ProductName = product.ProductName;
                r.ProductCode = product.ProductCode;
                r.BomItemId = bomItem.Id;
                r.UnitDose = bomItem.UnitDose;
                r.LossRate = bomItem.LossRate;
                r.StgQty = -1;
                r.PickQty = wo.Qty * bomItem.UnitDose;
                results.Add(r);
            }
            return results;

        }

        /// <summary>
        /// 根据工单任务和领料，创建出库申请单
        /// </summary>
        /// <returns></returns>
        public InvOappEntity CreatedInvOappByWoTask(string userNo, ProdWoTaskEntity wt, List<ProdMaintainPickItem> pickItems)
        {
            if (wt == null)
                return null;
            if (pickItems == null)
                return null;
            if (pickItems.Count == 0)
                return null;
            var oapp = new InvOappEntity();
            oapp.Id = Guid.NewGuid().ToString();
            oapp.CreatedBy = userNo;
            oapp.CreatedDate = DateTime.Now;
            oapp.UpdatedBy = userNo;
            oapp.UpdatedDate = DateTime.Now;
            oapp.IsActive = 1;
            oapp.AppNo = MstCodeRuleBs.GetCurrentOrderCode("IOA");
            oapp.Type = (int)Common.InvOutType.工单领料出库;
            oapp.RelatedId = wt.Id;
            oapp.Status = Common.WfStatus.WFS10.ToString();

            var oappi = new List<InvOappiEntity>();
            foreach (var pickItem in pickItems)
            {
                var invOappi = new InvOappiEntity();
                invOappi.Id = Guid.NewGuid().ToString();
                invOappi.OoAppId = oapp.Id;
                invOappi.ProductId = pickItem.ProductId;
                invOappi.Qty = pickItem.PickQty;
                oappi.Add(invOappi);
            }
            if (ESOL.Business.Inv.InvOappBs.CreateOapp(oapp, oappi))
            {
                return oapp;
            }
            else return null;

        }

        #region 生产计划
        public string WorkPlanWfEnd(ProdMaintainPo po)
        {
            try
            {
                if (po == null)
                    return "没指定生产计划";
                ProdPlanOrderEntity workplan = ProdPlanOrderBs.GetProdPlanOrder(new ProdPlanOrderEntity { Id = po.Id });
                if (workplan == null) return "没有找到生产计划实体" + po.Id;
                workplan.Status = Common.ProductPlanOrderStatus.PSTATUS06.ToString();
                workplan.IsActive = 1;
                if (!ProdPlanOrderBs.UpdateProdPlanOrder(workplan)) return "实体状态更新失败";
                return null;
            }
            catch (Exception ex)
            {
                MyDebug.write("WorkPlanWfEnd:" + ex.Message);
                return ex.Message;
            }

        }

        public string WorkPlanWfStart(ProdMaintainPo po)
        {
            try
            {
                if (po == null)
                    return "没指定生产计划";
                ProdPlanOrderEntity workplan = ProdPlanOrderBs.GetProdPlanOrder(new ProdPlanOrderEntity { Id = po.Id });
                if (workplan == null) return "没有找到生产计划实体" + po.Id;
                workplan.Status = Common.ProductPlanOrderStatus.PSTATUS08.ToString();

                if (!ProdPlanOrderBs.UpdateProdPlanOrder(workplan)) return "实体状态更新失败";
                return null;
            }
            catch (Exception ex)
            {
                MyDebug.write("WorkPlanWfEnd:" + ex.Message);
                return ex.Message;
            }

        }

        public List<ProdPlanOrderEntity> GetUpdateScheduleRelationPoList(string poId)
        {
            try
            {
                return ProdPlanOrderBs.GetUpdateScheduleRelationPoList(poId);
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public DataSet GetNotFinishPoAndWos()
        {

            try
            {
                DataSet woEntityList = ProdWoBs.GetNotFinishPoAndWos();
                return woEntityList;
            }
            catch (Exception ex)
            {
                MyDebug.write(ex.Message);
                return null;
            }
        }


        public DTODataTable GetProductionReqQty(string poNo)
        {
            DTODataTable output = new DTODataTable();
            try
            {
                DataSet ds = ProdPlanOrderBs.GetProductionReqQty(poNo);
                if (ds != null && ds.Tables.Count > 0)
                    output.result = ds.Tables[0];
                return output;
            }
            catch (Exception ex)
            {
                MyDebug.write(ex.Message);
                output.ErrorCode = "GetProductionReqQty";
                output.ErrorMessage = ex.Message;
                return output;
            }
        }


        public DTODataTable GetProductionSalesBalanceQuery()
        {
            DTODataTable output = new DTODataTable();
            try
            {
                DataSet ds = ProdPlanOrderBs.GetProductionSalesBalanceQuery();
                if (ds != null && ds.Tables.Count > 0)
                    output.result = ds.Tables[0];
                return output;
            }
            catch (Exception ex)
            {
                MyDebug.write(ex.Message);
                output.ErrorCode = "GetProductionSalesBalanceQuery";
                output.ErrorMessage = ex.Message;
                return output;
            }
        }
        #endregion

        #region 工单
        //
        public List<ProdMaintainWo> CreateWo(string userNo, string productId, string bomId, decimal planQty)
        {
            List<ProdWoEntity> woList = ProdWoBs.CreateWo(userNo, productId, bomId, planQty);
            if (woList == null) return null;
            List<ProdMaintainWo> woOutput = new List<ProdMaintainWo>();
            ProdMaintainWo output;
            string connectionString = MyConfig.getConnection("myconstring");
            PowerService ps = new PowerService(new BPM.Foundation.PWDB.PWDBDataContext(connectionString));
            PW_User createdUser = ps.getUser(null, userNo);
            foreach (ProdWoEntity wo in woList)
            {
                output = Common.CommonFunction.CopyEntityToServiceOutPut<ProdMaintainWo, ProdWoEntity>(wo);
                if (output != null)
                {
                    output.CreatedUser = createdUser.firstName;
                    output.RequiredDate = wo.ReqDate;
                    output.PlanStartDate = wo.PlanStartDate;
                    output.UpdatedUser = createdUser.firstName;
                    output.WoQty = wo.Qty;
                    woOutput.Add(output);
                }
            }
            return woOutput;

        }


        public bool SaveWoList(List<ProdMaintainWo> woList)
        {
            return ProdWoBs.SaveWoList(woList);
        }

        public bool UpdateWoList(List<ProdMaintainWo> woList)
        {
            return ProdWoBs.UpdateWoList(woList);
        }

        public bool UpdateProdWo(ProdWoEntity wo)
        {
            return ProdWoBs.UpdateProdWo(wo);
        }

        public List<ProdMaintainWo> GetProdWoByPoId(string planOrderId)
        {
            List<ProdMaintainWo> woList = new List<ProdMaintainWo>();
            List<ProdWoEntity> woEntityList = ProdWoBs.GetProdWoByPoId(planOrderId);
            if (woEntityList == null) return woList;
            ProdMaintainWo output;
            string connectionString = MyConfig.getConnection("myconstring");
            PowerService ps = new PowerService(new BPM.Foundation.PWDB.PWDBDataContext(connectionString));
            ProdPlanOrderEntity planOrder = ProdPlanOrderBs.GetProdPlanOrder(new ProdPlanOrderEntity { Id = planOrderId });

            foreach (ProdWoEntity wo in woEntityList)
            {

                output = Common.CommonFunction.CopyEntityToServiceOutPut<ProdMaintainWo, ProdWoEntity>(wo);
                if (output != null)
                {
                    PW_User createdUser = ps.getUser(null, wo.CreatedBy);
                    output.CreatedUser = createdUser.firstName;
                    output.RequiredDate = wo.ReqDate;
                    output.PlanStartDate = wo.PlanStartDate;
                    output.UpdatedUser = createdUser.firstName;
                    output.WoQty = wo.Qty;
                    output.PoNo = planOrder.PoNo;
                    woList.Add(output);
                }
            }

            return woList;
        }

        public ProdWoEntity GetProdWoByWoNo(string woNo)
        {
            return ProdWoBs.GetProdWo(new ProdWoEntity { WoNo = woNo });
        }


        #endregion


        #region 工单用料
        public List<ProdWoMtrlEntity> GetProdWoMtrlByPoNo(string poNo)
        {
            return ProdWoMtrlBs.GetProdWoMtrlByPoNo(poNo);
        }

        public List<ProdWoMtrlEntity> GetProdWoMtrlByWoNo(string woNo)
        {
            return ProdWoMtrlBs.GetProdWoMtrlByWoNo(woNo);
        }

        public DataSet GetProdWoMtrlDsByWoNo(string woNo)
        {
            return ProdWoMtrlBs.GetProdWoMtrlDsByWoNo(woNo);
        }


        #endregion


        #region 工单任务
        //获取每个工单的可报工工序和数量
        public DataSet GetWoAllowRptWorkQtyDsBySql(ProdWoTaskCondition condition)
        {

            return ProdWoTaskBs.GetWoAllowRptWorkQtyDsBySql(condition);
        }

        //获取每个工单指定工作组的可报工工序和数量
        public DataSet GetWoAllowRptWorkQtyDsByWorkGroup(ProdWoTaskCondition condition)
        {
            return ProdWoTaskBs.GetWoAllowRptWorkQtyDsByWorkGroup(condition);
        }


        public List<ProdWipCurEntity> GetProdWipCurByCondition(ProdWipCurEntity conidtion)
        {
            return ProdWipCurBs.GetProdWipCurByCondition(conidtion);
        }

        public List<ProdWipMtrlCurEntity> GetProdWipMtrlCurByCondition(ProdWipMtrlCurEntity conidtion)
        {
            return ProdWipMtrlCurBs.GetProdWipMtrlCurByCondition(conidtion);
        }

        public DataSet GetProdWipMtrlCurDsByCondition(ProdWipMtrlCurEntity conidtion)
        {
            return ProdWipMtrlCurBs.GetProdWipMtrlCurDsByCondition(conidtion);
        }

        //报工
        public string ReportWork(ProdWipCurEntity wip, ProdWipHisEntity his)
        {
            try
            {
                bool re = ProdWipCurBs.ReportWork(wip, his);
                if (re) return "";
                else return "报工不成功！";
            }
            catch (Exception ex)
            {
                MyDebug.write("ReportWork:" + ex.Message);
                return ex.Message;
            }
        }

        public DataSet GetWipProc(ProdWoQueryCondition condition)
        {
            try
            {
                return ProdWipCurBs.GetWipProc(condition);
            }
            catch (Exception ex)
            {
                MyDebug.write("GetWipProc:" + ex.Message);
                return null;
            }
        }

        public DataSet GetWip(ProdWoQueryCondition condition)
        {
            try
            {
                return ProdWipCurBs.GetWip(condition);
            }
            catch (Exception ex)
            {
                MyDebug.write("GetWipProc:" + ex.Message);
                return null;
            }
        }


        public DataSet GetWipHisProcs(ProdWoTaskCondition condition)
        {
            try
            {
                return ProdWipHisBs.GetWipHisProcs(condition);
            }
            catch (Exception ex)
            {
                MyDebug.write("GetWipHisProcs:" + ex.Message);
                return null;
            }
        }

        public DataSet GetWipKPI(ProdWoTaskCondition condition)
        {
            try
            {
                return ProdWipHisBs.GetWipKPI(condition);
            }
            catch (Exception ex)
            {
                MyDebug.write("GetWipKPI:" + ex.Message);
                return null;
            }
        }


        public string WipLogon(ProdWipCurEntity wip, ProdWipHisEntity his)
        {
            try
            {
                bool re = ProdWipCurBs.WipLogon(wip, his);
                if (re)
                    return "";
                else
                    return "入帐失败！";
            }
            catch (Exception ex)
            {
                MyDebug.write("WipLogon:" + ex.Message);
                return ex.Message;
            }
        }


        public DataSet GetWoAllowLogonQtyDsBySql(ProdWoTaskCondition condition)
        {

            return ProdWipCurBs.GetWoAllowLogonQtyDsBySql(condition);
        }


        public DataSet GetFinishedWip(string woNo)
        {
            return ProdWipCurBs.GetFinishedWip(woNo);
        }

        public string WipOffLine(DataSet offlineWips)
        {
            try
            {
                if (ProdWipCurBs.WipOffLine(offlineWips))
                    return "";
                else
                    return "下线失败";
            }
            catch (Exception ex)
            {
                MyDebug.write("WipOffLine:" + ex.Message);
                return ex.Message;
            }
        }

        public string WipInventory(DataSet InventoryWips)
        {
            try
            {
                if (ProdWipCurBs.WipOffLine(InventoryWips))
                    return "";
                else
                    return "入库申请保存失败";

            }
            catch (Exception ex)
            {
                MyDebug.write("WipInventory:" + ex.Message);
                return ex.Message;
            }
        }
        #endregion

        #region 工作组
        public List<ProdWorkgroupEntity> GetWorkGroupByCondition(ProdWorkgroupEntity conidtion)
        {
            List<ProdWorkgroupEntity> workgroups = ProdWorkgroupBs.GetProdWorkgroupByCondition(conidtion);
            string connectionString = MyConfig.getConnection("myconstring");
            PowerService ps = new PowerService(new BPM.Foundation.PWDB.PWDBDataContext(connectionString));
            if (workgroups != null)
            {
                foreach (ProdWorkgroupEntity entity in workgroups)
                {
                    if (!string.IsNullOrEmpty(entity.CreatedBy))
                    {
                        var createdUser = ps.getUser(null, entity.CreatedBy);
                        if (createdUser != null)
                            entity.CreatedUser = createdUser.firstName;
                    }
                    if (!string.IsNullOrEmpty(entity.UpdatedBy))
                    {
                        var createdUser = ps.getUser(null, entity.UpdatedBy);
                        if (createdUser != null)
                            entity.UpdatedUser = createdUser.firstName;
                    }
                    if (!string.IsNullOrEmpty(entity.UserNo))
                    {
                        var createdUser = ps.getUser(null, entity.UserNo);
                        if (createdUser != null)
                            entity.KeyUser = createdUser.firstName;
                    }

                }
            }


            return workgroups;
        }


        public ProdWorkgroupEntity GetWorkGroupByKey(string workGroupId)
        {
            ProdWorkgroupEntity entity = ProdWorkgroupBs.GetProdWorkgroup(new ProdWorkgroupEntity { Id = workGroupId });
            string connectionString = MyConfig.getConnection("myconstring");
            PowerService ps = new PowerService(new BPM.Foundation.PWDB.PWDBDataContext(connectionString));
            if (!string.IsNullOrEmpty(entity.CreatedBy))
            {
                var createdUser = ps.getUser(null, entity.CreatedBy);
                entity.CreatedUser = createdUser.firstName;
            }
            if (!string.IsNullOrEmpty(entity.UpdatedBy))
            {
                var createdUser = ps.getUser(null, entity.UpdatedBy);
                entity.UpdatedUser = createdUser.firstName;
            }
            if (!string.IsNullOrEmpty(entity.UserNo))
            {
                var createdUser = ps.getUser(null, entity.UserNo);
                entity.KeyUser = createdUser.firstName;
            }
            return entity;
        }


        public string AddProdWorkGroup(ProdWorkgroupEntity workgroupEntity, List<ProdWorkgroupUserEntity> workgroupUsers)
        {
            try
            {
                bool re = ProdWorkgroupBs.InsertProdWorkgroup(workgroupEntity, workgroupUsers);
                if (re)
                {
                    return "";
                }
                else
                    return "保存失败";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }

        }

        public string UpdateProdWorkGroup(ProdWorkgroupEntity workgroupEntity, List<ProdWorkgroupUserEntity> workgroupUsers)
        {
            try
            {
                workgroupEntity.UpdatedDate = DateTime.Now;
                bool re = ProdWorkgroupBs.UpdateProdWorkgroup(workgroupEntity, workgroupUsers);
                if (re)
                {
                    return "";
                }
                else
                    return "保存失败";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }

        }


        public string DeleteProdWorkGroup(ProdWorkgroupEntity workgroupEntity)
        {
            try
            {
                bool re = ProdWorkgroupBs.DeleteProdWorkgroup(workgroupEntity);
                if (re)
                {
                    return "";
                }
                else
                    return "删除失败";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }

        }


        public List<ProdWorkgroupUserEntity> GetWorkGroupUsersByWorkGroupId(string workgroupId)
        {
            return ProdWorkgroupBs.GetWorkGroupUsersByWorkGroupId(workgroupId);
        }
        #endregion


        #region 委外加工


        public string UpdateCooperationOrder(ProdCooperationOrderEntity entity)
        {
            try
            {
                bool result = ProdCooperationOrderBs.UpdateProdCooperationOrder(entity);
                if (result)
                    return "";
                else
                    return "修改失败！";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }


        public string AddCooperationOrder(ProdCooperationOrderEntity entity)
        {
            try
            {
                if (string.IsNullOrEmpty(entity.OrderCode))
                    entity.OrderCode = MstCodeRuleBs.GetCurrentOrderCode("ProductionCooperation");
                bool result = ProdCooperationOrderBs.InsertProdCooperationOrder(entity);
                if (result)
                    return "";
                else
                    return "新增失败！";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }


        public string DeleteCooperationOrder(ProdCooperationOrderEntity entity)
        {
            try
            {
                bool result = ProdCooperationOrderBs.DeleteProdCooperationOrder(entity);
                if (result)
                    return "";
                else
                    return "新增失败！";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }



        public List<ProdCooperationOrderEntity> GetCooperationOrderList(ProdCooperationOrderEntity entity)
        {
            try
            {
                List<ProdCooperationOrderEntity> result = ProdCooperationOrderBs.GetProdCooperationOrderByCondition(entity);
                foreach (ProdCooperationOrderEntity c in result)
                {
                    ProdWoEntity wo = ProdWoBs.GetProdWo(new ProdWoEntity { WoNo = c.WoNo });
                    ProdPlanOrderEntity po = ProdPlanOrderBs.GetProdPlanOrder(new ProdPlanOrderEntity { Id = wo.PoId });
                    c.PoNo = po.PoNo;
                    c.ContractModel = po.ContractModel;
                }
                return result;
            }
            catch (Exception ex)
            {
                return null;
            }
        }



        public DataSet GetProdCooperationOrderDsByCondition(ProdCooperationOrderEntity entity)
        {
            try
            {
                DataSet result = ProdCooperationOrderBs.GetProdCooperationOrderDsByCondition(entity);
                DataTable dt = result.Tables[0];
                dt.Columns.Add("PO_NO", typeof(string));
                dt.Columns.Add("CONTRACT_MODEL", typeof(string));
                foreach (DataRow c in dt.Rows)
                {
                    ProdWoEntity wo = ProdWoBs.GetProdWo(new ProdWoEntity { WoNo = c["WO_NO"].ToString() });
                    ProdPlanOrderEntity po = ProdPlanOrderBs.GetProdPlanOrder(new ProdPlanOrderEntity { Id = wo.PoId });
                    c["PO_NO"] = po.PoNo;
                    c["CONTRACT_MODEL"] = po.ContractModel;
                }
                return result;
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public string UpdateCooperationOrderList(List<ProdCooperationOrderEntity> entityList)
        {
            try
            {

                string result = ProdCooperationOrderBs.UpdateProdCooperationOrderList(entityList);

                return result;

            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }

        #endregion


        #region 生产相关查询

        //生产日报表
        public DataSet GetWorkDaily(DateTime date)
        {
            return ProdWipHisBs.GetWorkDaily(date);
        }
        #endregion


        #region 生产维修

        public DataSet GetProdWipMtrlHisDsByCondition(ProdWipMtrlHisEntity condition)
        {
            return ProdWipMtrlHisBs.GetProdWipMtrlHisDsByCondition(condition);
        }


        public DataSet GetAllowedRepairQty(ProdWipCurEntity condition)
        {
            return ProdWipCurBs.GetAllowedRepairQty(condition);
        }

        public string ProdRepairWork(ProdWipCurEntity wip, ProdWipHisEntity his, DataTable DisAssembleMtrls, DataTable AssembleMtrls)
        {
            try
            {
                string re = ProdWipCurBs.ProdRepairWork(wip, his, DisAssembleMtrls, AssembleMtrls);
                return re;
            }
            catch (Exception ex)
            {
                MyDebug.write("ProdRepairWork:" + ex.Message);
                return ex.Message;
            }
        }
        #endregion


        #region
        //过程质检
        public string QCReportWork(ProdWipCurEntity wip, ProdWipHisEntity his, Common.DTO.IpqcSaveParam param)
        {
            try
            {
                bool re = ProdWipCurBs.QCReportWork(wip, his, param);
                if (re) return "";
                else return "质检不成功！";
            }
            catch (Exception ex)
            {
                MyDebug.write("QCReportWork:" + ex.Message);
                return ex.Message;
            }
        }
        #endregion

        public bool TestConnect()
        {
            return true;
        }

    }
}
